﻿using iText.Bouncycastle.Crypto;
using iText.Commons.Bouncycastle.Crypto;
using iText.Signatures;
using Org.BouncyCastle.Crypto.Signers;

namespace Base.FileService.Pdf
{
    internal class Sm2SignExtend : IExternalSignature
    {
        private readonly ISigner _Sm2;
        private readonly IPrivateKey _Pk;
        public Sm2SignExtend ( IPrivateKey pk )
        {
            this._Pk = pk;
            this._Sm2 = new SignerBC(new SM2Signer());
        }
        public string GetDigestAlgorithmName ()
        {
            return "SM3";
        }

        public string GetSignatureAlgorithmName ()
        {
            return "SM2";
        }

        public ISignatureMechanismParams GetSignatureMechanismParameters ()
        {
            return null;
        }

        public byte[] Sign ( byte[] message )
        {
            this._Sm2.InitSign(this._Pk);
            this._Sm2.Update(message);
            return this._Sm2.GenerateSignature();
        }
    }
}
